package com.csdj.t309.papermanage.controller;

import com.csdj.t309.papermanage.common.WebResult;
import com.csdj.t309.papermanage.entity.TUser;
import com.csdj.t309.papermanage.service.ITUserService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/tuser")
public class TUserController {
    @Resource
    private ITUserService itUserService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @ResponseBody
    @PostMapping("/login")
    public WebResult login(@RequestParam(value = "userCode",required = false) String userCode,
                           @RequestParam(value = "userPassword",required = false) String userPassword){
        TUser tUser = itUserService.login(userCode,userPassword);
        WebResult webResult = new WebResult();
        if(tUser!=null){
            stringRedisTemplate.opsForValue().set("paperuserid",Integer.toString(tUser.getId()));
            webResult.putData("tUser",tUser);
            return webResult;
        }
        return null;
    }

}
